//公众函数
import {
    Toast
} from 'mint-ui';
export default {
    login: function () {
        //console.log("1111");
    },
    getQuery(event) {
        return event.$route.query
    },
    wjwData: '',
    getpersondata(event) {
        let persondata = localStorage.wjwdata;
        if (persondata) {
            return this.wjwData = JSON.parse(persondata);
        } else {
            // Toast({
            //     message: '系统检测到您还没有登录，3s后跳转到登录页！',
            //     position: 'center',
            //     duration: 2000
            // });
            // setTimeout(() => {
            //     event.$router.push('/login');
            // }, 2000);
        }
    },
    logout(event) {
        Toast({
            message: '退出成功，返回登录页',
            position: 'center',
            duration: 2000
        });
        localStorage.removeItem("wjwdata");
        setTimeout(() => {
            event.$router.push('/login');
        }, 2000);
    },
    tijiaoResult(code) {

    },
    //baseURL:'http://localhost:8001/apis',
    //baseURL:'http://zadai.net:8001/apis',
    baseURL: 'apis',
    loginCheak(event, code) {
        if (code == -8) {
            Toast({
                message: '请登录，2s后跳转到登录页',
                position: 'center',
                duration: 2000
            });
            setTimeout(() => {
                event.$router.push('/login');
            }, 2000);
            return
        }
    },
    formatDate(odata) {
        let dateee = new Date(odata).toJSON();
        return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
    },
    //获取用户列表
    getCuslist(event, customType, pageNum, pageSize) {
        console.log(customType)
        sessionStorage.tabIerd = customType
        event.axios({
            method: 'get',
            headers: {
                'Content-Type': 'application/json'
            },
            url: this.baseURL + '/wxpulic/getCustom/' + customType + '/' + pageNum + '/' + pageSize,
            // url: this.baseURL+'/wxpulic/getCustom/'+customType+'/'+pageNum+'/'+pageSize,
            data: {
                customType: customType,
                pageNum: pageNum,
                pageSize: pageSize
            },
            withCredentials: true,
        }).then((response) => {
            this.loginCheak(event, response.data.code); //检测是否登录
            if (response.data.code == 0) {
                response.data.data.dataList.forEach((value, index) => {
                    let _img = "";
                    switch (value.customType) {
                        case "0":
                            _img = require('../img/cus_yixiang.png');
                            break
                        case "1":
                            _img = require('../img/cus_baojian.png');
                            break
                        case "2":
                            _img = require('../img/cus_over.png');
                            break
                        default:
                            _img = require('../img/cus_yixiang.png');
                            break
                    }
                    let feednewback = "";
                    if (value.lastFeedBack) {
                        feednewback = value.lastFeedBack
                    }
                    let _zizhi = "资金需求:" + value.wantMoney + "万";
                    if (value.planStatus == "不具备报件条件") {
                        //_zizhi = value.planStatus+"  "+feednewback;
                        _zizhi = feednewback;
                    } else if (value.planStatus == "已完成") {
                        //_zizhi = "放款额:"+value.wantMoney+"万"+"  "+feednewback;
                        _zizhi = feednewback;
                    }
                    let obj = {
                        authname: value.name,
                        time: value.updateTime,
                        phone: value.mobile,
                        zijin: _zizhi,
                        oid: value.id,
                        authorImg: _img,
                        oType: value.customType
                    }
                    event.odata.push(obj);
                });
                if (response.data.data.totalPage > pageNum + 1) {
                    event.addmore = "加载更多...";
                } else {
                    event.addmore = "暂无更多";
                }
            } else {
                console.log(response)
            }
        }).catch((error) => {
            console.log(error)
        });
    },
    //获取注册用户列表
    getCusregister(event, pageNum, pageSize) {
        event.axios({
            method: 'get',
            // headers:{
            //     'Content-Type':'application/json'
            // },
            url: this.baseURL + '/wxpulic/listRegistCustom?pageNum=0&pageSize=10',
            data: {
                pageNum: 0,
                pageSize: 10
            },
            withCredentials: true,
        }).then((response) => {
            //console.log(response)
            this.loginCheak(event, response.data.code); //检测是否登录
            if (response.data.code == 0) {
                response.data.data.dataList.forEach((value, index) => {
                    let obj = {
                        authorImg: value.image,
                        // authorImg:require('../img/ceshi.jpg'),
                        nikeName: value.nikeName,
                        otime: value.creationTime,
                        phone: value.mobile,
                        id: value.id
                    }
                    event.odata.push(obj);
                });
                if (response.data.data.totalPage > pageNum + 1) {
                    event.addmore = "加载更多...";
                } else {
                    event.addmore = "暂无更多";
                }
            } else {
                console.log(response)
            }
        }).catch((error) => {
            console.log(error)
        });
    },
    //获取跟进记录列表
    getGenjinlist(event, oid) {
        event.genList = [];
        event.axios({
            method: 'get',
            headers: {
                'Content-Type': 'application/json'
            },
            url: event.common.baseURL + '/wxpulic/customFollowList/' + oid,
            // url: '/apis/wxpulic/customFollowList/'+oid,
            data: {},
            withCredentials: true,
        }).then((response) => {
            let oresponse = event.qs.parse(response)
            if (oresponse.data.code == 0) {
                oresponse.data.data.forEach((item, i) => {
                    event.genList.push({
                        content: item.content,
                        creationTime: item.creationTime
                    });
                });
            }
        }).catch((error) => {
            console.log(error)
        });
    }
}
